package com.hnqcgczy.dao;

import com.hnqcgczy.vo.TUser;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class UseDaolmplImpl extends UseDaolmpl {
    private  MyTransaction myTransaction;

    public static void main(String[] args) {
        MyTransaction myTransaction = new MyTransaction(true);
        UseDaolmplImpl useDaolmpl = new UseDaolmplImpl(myTransaction);
        try {
            boolean b = useDaolmpl.login("admin123","admin");
            System.out.println(b);
        }catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        }
    public UserDaoImpl(MyTransaction myTransaction) {
        this.myTransaction = myTransaction;//赋值

    }



    @Override
    public boolean login(String tu_id, String tu_password) throws SQLException {
        Connection conn = myTransaction.getConn();
        String sql = "select * from  t_user where tu_id=? and tu_password=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        //给？注入值
        ps.setString(1, tu_id);
        ResultSet rs = ps.executeQuery();
        boolean flag = false;
        while (rs.next()) {
            flag = true;
        }
        //释放资源
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
        //关闭数据库 在业务层
        return false;
    }



    @Override
    public boolean reg(String tu_id, String tu_password) throws SQLException {
        return false;
    }

    @Override
    public List<TUser> getAll() throws SQLException {
        return null;
    }

    @Override
    public TUser getUserByID(String tu_id) throws SQLException {
        return null;
    }

    @Override
    public List<TUser> getUsersByName(String tu_name) throws SQLException {
        return null;
    }

    @Override
    public List<TUser> getUserByAny(Object... obj) throws SQLException {
        return null;
    }

    @Override
    public boolean update(TUser tUser) throws SQLException {
        return false;
    }

    @Override
    public boolean deleteById(String tu_id) throws SQLException {
        return false;
    }

    @Override
    public boolean querByID(String tu_id) throws SQLException {
        return false;
    }

    @Override
    public boolean inssert(String tu_id, String tu_password) {
        return false;
    }
}
